/
 * 商品标签
 */
<template>
  <div class="Goods">
    <div class="main" style="border-radius: 5px">
      <!--列表-->
      <div class="banManage">
        <span class="classifications" @click="addLable">添加标签</span>
        <span :class="multipleSelection && multipleSelection.length > 0? 'classifications': 'classification'" @click="dellist()">批量删除</span>
      </div>
      <div class="tableBox">
        <div class="shopContent">
          <el-table
            :data="shopData"
            @selection-change="handleSelectionChange"
            size="small" 
            v-loading="loading"
            height="70vh"
            element-loading-text="拼命加载中"
            style="width: 100%"
            :header-cell-style="{
              color: '#3D3D3D',
              'font-size': '22px',
              height: '60px',
              'font-weight': '400',
              'background-color': '#F8F9FB',
              'border-bottom': 'none',
            }"
            class="customer-table"
            :row-class-name="tableRowClassName"
          >
            <el-table-column
              type="selection"
              width="100"
              align="center"
            ></el-table-column>
            <el-table-column prop="name" label="标签名称" width="200%">
            </el-table-column>
            <el-table-column
              prop="number"
              label="标签绑定商品数"
              main-width="16%"
              align="center"
            ></el-table-column>
            <el-table-column label="操作" main-width="16%" align="center">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  style="font-size: 0.875rem; color: #436af2"
                  @click="handleEdits(scope.$index, scope.row)"
                  >编辑</el-button
                >
                <el-button
                  type="text"
                  style="font-size: 0.875rem; color: #436af2"
                  @click="deleteUser(scope.$index, scope.row)"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!-- 编辑弹框 -->
      <el-dialog :visible.sync="editFormLable" width="380px">
        <span class="nav">编辑标签</span>
        <div class="navBox">
          <el-form label-width="100px" :model="formLable"
            ><!-- :model="formList"表单数据对象 -->
            <el-form-item label="标签名称：">
              <el-input
                placeholder="请输入名称"
                v-model="formLable.name"
                maxlength="5"
                show-word-limit
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
        <span slot="footer" class="shopFooter">
          <el-button
            @click="submitForms('formLable')"
            style="
              width: 100%;
              padding: 0.75rem 0;
              background-color: #436af2;
              color: #fff;
              font-size: 0.875rem;
              border-radius: 5px;
            "
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 添加标签 -->
      <el-dialog :visible.sync="addFormLables" width="380px">
        <span class="nav">添加标签</span>
        <div class="navBox">
          <el-form label-width="100px" :model="addFormLable"
            ><!-- :model="formList"表单数据对象 -->
            <el-form-item label="标签名称：">
              <el-input
                placeholder="请输入名称"
                v-model="addFormLable.name"
                maxlength="5"
                show-word-limit
              ></el-input>
            </el-form-item>
          </el-form>
        </div>
        <span slot="footer" class="shopFooter">
          <el-button
            @click="addsubmit('addFormLable')"
            style="
              width: 100%;
              padding: 0.75rem 0;
              background-color: #436af2;
              color: #fff;
              font-size: 0.875rem;
              border-radius: 5px;
            "
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 分页 -->
      <div class="paging">
        <div class="pagiton">
          <button class="btn btn-default" type="submit" @click="prePage">
            <i class="el-icon-caret-left"></i>
          </button>
          <button class="btn btn-defaults" type="submit">
            {{ current_page }}
          </button>
          <button
            class="btn btn-default"
            type="submit"
            @click="nextPage"
            :class="{ disabled: disableds }"
          >
            <i class="el-icon-caret-right"></i>
          </button>
          <p class="remarks">
            共 <span> {{ pagesize }} </span>条当前为第
            <span> {{ currentPage }} </span>页
          </p>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      currentPage: 1, //当前页号
      pagesize:20, //每页大小
      disableds: false,
      loading: false,
      shopData: [],
      editFormLable: false,
      addFormLables: false,
      formLable: {
        name: "",
        id: "",
      },
      addFormLable: {
        name: "",
        id: "",
      },
      sort: "",
      multipleSelection:''
    };
  },
  computed: {
    page_arrs() {
      let { currentPage, pagesize } = this;
      return this.shopData.slice(
        (currentPage - 1) * pagesize,
        currentPage * pagesize
      );
    },
    current_page() {
      return this.currentPage;
    }
  },
  created() {
    this.labeList();
  },
  methods: {
    //标签列表
    labeList() {
      this.loading - true;
      this.$axios({
        method: "post",
        url: "goods/goods_type_list",
        params:{
          p:this.currentPage,
          size:this.pagesize
        }
      }).then((res) => {
        if(res.data.data.length<20){
          this.disableds=true
        }else{
          this.disableds=false
        }
        this.shopData = res.data.data;
        
      });
    },
    //添加标签
    addsubmit() {
      this.$axios({
        method: "post",
        url: "/goods/save_goods_type",
        params: {
          // id:this.addFormLable.id,
          name: this.addFormLable.name,
          sort: this.sort,
        },
      }).then((res) => {
        this.labeList();
        (this.addFormLables = false), console.log(res, "添加标签列表");
      });
    },
    //编辑确定
    submitForms() {
      this.$axios({
        method: "post",
        url: "/goods/save_goods_type",
        params: {
          id: this.formLable.id,
          name: this.formLable.name,
          sort: this.sort,
        },
      }).then((res) => {
        this.labeList();
        (this.editFormLable = false), console.log(res, "编辑标签列表");
      });
    },
    //编辑
    handleEdits(index, row) {
      this.editFormLable = true;
      this.formLable.name = row.name;
      this.formLable.id = row.id;
      this.sort = row.sort;
      console.log(this.addFormLable.name, "111");
    },
    //删除
    deleteUser(index, row) {
      this.$confirm("确定要删除轮播图吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios({
            method: "post",
            url: "goods/del_goods_type",
            params: {
              id: row.id,
            },
          }).then((res) => {
            if (res.status) {
              this.labeList();
              this.$message({
                type: "success",
                message: "删除成功",
              });
            }
          });
        })
        .catch((err) => {
          this.loading = false;
          this.$message({
            type: "error",
            message: "删除失败",
          });
        });
    },
    // 序号选择操作
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 批量删除列表数据
    dellist(){

    },
    addLable() {
      this.addFormLables = true;
      this.addFormLable.name=''
    },
    //隔行换色
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 0) {
        return "success-row";
      } else {
        return "warning-row";
      }
      return "";
    },
    //分页
    prePage() {
      this.disableds=false
      if (this.currentPage == 1){
        return;
      }
      this.currentPage = this.currentPage - 1;
      this.labeList()
    },
    nextPage() {
      if (this.currentPage == Math.ceil(this.shopData.length)) {
        return;
      }
      this.currentPage = this.currentPage + 1;
      this.labeList()
    },
  },
};
</script>
<style scoped>
.disabled {
  /* 鼠标会显示不可点 */
  cursor: not-allowed;
  /* 会阻止事件 */
  pointer-events: none;
}
.shopContent .el-button:hover{
  font-weight: bold;
}
/* 分页 */
.pagiton {
  text-align: center;
  padding-bottom: 10px;
  display: flex;
  width: 280px;
  align-items: center;
  margin: 0 auto;
  padding-top:50px;
}
.pagiton .btn-defaults {
  background-color: #436af2;
  border-radius: 5px;
  font-size: 0.875rem;
  color: #fff;
  border: 1px solid #436af2;
  height: 28px;
  width: 28px;
  line-height: 28px;
  margin: 0 10px;
}
.pagiton .btn-default {
  background-color: #fff;
  border: 1px solid #f7f7f7;
  color: #c1c1c1;
  height: 28px;
  width: 32px;
  line-height: 28px;
  font-size: 0.875rem;
}
.pagiton .remarks {
  margin: 10px 0;
  color: #ababab;
  font-size: 0.875rem;
  padding-left: 5px;
}
.main {
  background-color: #fff;
  box-sizing: border-box;
  overflow: hidden;
}
.banManage {
  background-color: #fff;
  padding: 0 20px;
  overflow: hidden;
  display: flex;
  /* justify-content: space-between;
  align-items: center; */
  margin-top: 1.5rem;
}
.banManage .classification {
  border: 1px solid #E3E2E5;
  width: 100px;
  height: 38px;
  line-height: 38px;
  cursor: pointer;
  border-radius: 5px;
  text-align: center;
  font-size: 0.875rem;
}
.banManage .classifications {
  border: 1px solid #6584f4;
  width: 100px;
  height: 38px;
  line-height: 38px;
  text-align: center;
  font-size: 0.875rem;
  cursor: pointer;
  color: #fff;
  background-color: #436af2;
  border-radius: 5px;
  margin-right: 10px;
}
.tableBox {
  background-color: #fff;
  padding: 15px 0px;
  font-size: 0.875rem;
  height: 70vh;
  width: 96%;
  margin-left: 2%;
}
.shopContent {
  width: 100%;
  margin-top: 0.875rem;
  background-color: #f8f9fb;
}
/* 弹框 */
.nav {
  font-size: 1.125rem;
  color: #3d3d3d;
  font-weight: bold;
  line-height: 60px;
}
/deep/.navBox .el-input {
  border-radius: 0;
  width: 100%;
}
/deep/.navBox .el-input__inner {
  width: 82%;
}
.navBox {
  margin-top: 0.875rem;
}
.shopFooter {
  text-align: center;
  display: inline-block;
  width: 110px;
  margin: 1.7rem 0;
  margin-right: 35%;
}
/deep/ .el-dialog {
  border-radius: 8px;
}
/deep/ .el-table td.el-table__cell,
.el-table th.el-table__cell.is-leaf {
  border-bottom: none;
}
/deep/ .el-table--small .el-table__cell {
  padding: 10px 0px;
}
/deep/ .el-table td.el-table__cell div {
  font-size: 0.875rem;
}
/deep/ .el-table th.el-table__cell > .cell {
  font-size: 15px;
}
/deep/ .el-table .warning-row {
  background: #f8f9fb !important;
}
/deep/ .el-table .success-row {
  background: white !important;
}
</style>